package x_yeyue.obj;

import x_yeyue.GameWin;
import x_yeyue.utils.GameUtils;

import java.awt.*;

public class BossObj extends GameObj{

    int health = 50;

    public BossObj(Image img, int x, int y, double speed) {
        super(img, x, y, speed);
    }

    public BossObj(Image img, int width, int height, int x, int y, double speed, GameWin frame) {
        super(img, width, height, x, y, speed, frame);
    }

    public BossObj() {
    }

    @Override
    public Rectangle getRec() {
        return super.getRec();
    }

    @Override
    public void paintSelf(Graphics g) {
        super.paintSelf(g);
        if(y < 40){
            y += speed;
        }else{
            x += speed;
            if(x < 0 || x > 360){
                speed = -speed;
            }
        }
        for (ShellObj shellObj : GameUtils.shellObjList) {
            if(this.getRec().intersects(shellObj.getRec()) && health > 0){
                // 碰撞之后出现爆炸动画
                ExplodeObj explodeObj = new ExplodeObj(x + 100, y + 100);
                GameUtils.explodeObjsList.add(explodeObj);
                GameUtils.removeList.add(explodeObj);

                shellObj.setX(-100);
                shellObj.setY(-100);
                GameUtils.removeList.add(shellObj);
                health --;
            }else if(this.getRec().intersects(shellObj.getRec()) && health <= 0){
                // 碰撞之后出现爆炸动画
                ExplodeObj explodeObj = new ExplodeObj(x + 100, y + 100);
                GameUtils.explodeObjsList.add(explodeObj);
                GameUtils.removeList.add(explodeObj);

                shellObj.setX(-100);
                shellObj.setY(-100);
                GameUtils.removeList.add(shellObj);
                GameWin.score += 10;
                GameUtils.removeList.add(this);
                GameWin.state = 4;
            }
        }
    }
}
